<?php 

// var_dump($_FILES);

function up($dir='./upload'){
foreach($_FILES as $v){
	foreach ($v['name'] as $key => $value) {
		// var_dump  ($value) ;
		// echo '<br />';
		// var_dump($v[tmp_name]);
		if(is_uploaded_file($v['tmp_name'][$key])){
			is_dir($dir) || mkdir($dir, 0777, true);
			//获得文件扩展名 
			// var_dump($v['name'][$key]);
			$type = ltrim(strrchr($v['name'][$key], '.'),'.');
			// echo 'type==>' .$type;
			//完整路径			
			$fullPath = $dir . '/' . date ('ymd_') . mt_rand(0, 99999) . '.' . $type;
			// echo 'fullpath==>' .$fullPath;
			//移动上传
			move_uploaded_file($v['tmp_name'][$key], $fullPath);
			echo $v['name'][$key].'上传成功  ';
		}


	}

}

}

up();



 // var_dump($_SERVER)  //打印系统变量


 ?>

  <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
 <head>
 	<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
 	<title>Document</title>
 	<script type="text/javascript" src='jquery-1.7.2.min.js' ></script>
 	<script type="text/javascript">
 	$(function(){
 		// 点击添加 复制上传按钮
 		$('#add').click(function() {

 			$('#upload').find('.first').eq(0).clone().insertAfter('.first:last');
 		});
 	})

 	</script>
 	<link rel="stylesheet" href="css/index.css" />
 </head>
 <body>
 	<form action="" method="post" enctype="multipart/form-data">
 		<div id="upload">
 		<input type="button" id="add" value="增加" /><br />
 		<li class="first">
 		<input type="file" name="up[]" id="" /><input type="submit" value="上传"/>
 		</li>
 		</div>
 		
 	</form>
 </body>
 </html>